VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsTraza"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Explicit

Private mvarimprimeEtiqueta     As Boolean
Private mvarGrupo               As Byte
Private mvarTC()                As TrazaCampos
Private mvarMaxIndice           As Integer
Private mvarElemTrz             As Long




Public Sub GuardaValoresTraza()
Dim rsElemTrz As ADODB.Recordset
Dim i As Integer


    Set rsElemTrz = New ADODB.Recordset

    With rsElemTrz
    
        .Open "SELECT * FROM [Elementos Trazables (Valores)]", Cn_Local, adOpenKeyset, adLockOptimistic
        
        For i = 1 To mvarMaxIndice
        
            If mvarTC(i).Valor <> "" Then
            
                .AddNew
                
                .Fields("Codigo_Elemento") = mvarElemTrz
                
                .Fields("Campo") = mvarTC(i).Orden
                
                If mvarTC(i).Tipo = 3 Then
                
                    .Fields("Texto") = mvarTC(i).ValorCombo
                    
                Else
                
                    .Fields("Texto") = mvarTC(i).Valor
                    
                End If
                
                If mvarTC(i).Tipo = 4 Then .Fields("Valor_Combo") = mvarTC(i).ValorCombo
                
                Update_Seguro rsElemTrz, FileLog
                
            End If
            
        Next i
        
        If .State = adStateOpen Then .Close
        
    End With

    Set rsElemTrz = Nothing
    
End Sub

Friend Function GetCampos(ByVal Indice As Integer) As TrazaCampos
    GetCampos = mvarTC(Indice)
End Function

Public Sub SetValor(ByVal Indice As Integer, ByVal ValCampo As String, Optional ByVal ValCombo As Integer = 0)
    mvarTC(Indice).Valor = ValCampo
    mvarTC(Indice).ValorCombo = ValCombo
End Sub

Public Sub LeeCamposTraza(ByVal Grupo As Byte)
Dim sqlStr As String
Dim rs_CamposTrz As ADODB.Recordset
    Set rs_CamposTrz = New ADODB.Recordset
    sqlStr = "SELECT Orden, Nombre, Tipo, Longitud, Ancho, Mostrar_Mercancias, Saltar_Mercancias FROM [Trazabilidad (Campos)] " & _
            "WHERE Grupo = " & Grupo
    With rs_CamposTrz
        .Open sqlStr, Cn_Local, adOpenStatic, adLockReadOnly
        mvarMaxIndice = .RecordCount
        If mvarMaxIndice <> 0 Then ' Si el grupo tiene campos definidos
            ReDim mvarTC(1 To mvarMaxIndice)
            .MoveFirst
            Do While Not .EOF
                mvarTC(.Fields("Orden").value).Orden = .Fields("Orden").value
                mvarTC(.Fields("Orden").value).Nombre = .Fields("Nombre").value & ""
                mvarTC(.Fields("Orden").value).Tipo = .Fields("Tipo").value
                mvarTC(.Fields("Orden").value).Longitud = .Fields("Longitud").value
                mvarTC(.Fields("Orden").value).Ancho = .Fields("Ancho").value
                mvarTC(.Fields("Orden").value).Mostrar = .Fields("Mostrar_Mercancias").value
                mvarTC(.Fields("Orden").value).Saltar = .Fields("Saltar_Mercancias").value
                .MoveNext
            Loop
        End If
        If .State = adStateOpen Then .Close
    End With
    Set rs_CamposTrz = Nothing

End Sub

Public Property Let imprimeEtiqueta(ByVal vData As Boolean)
    mvarimprimeEtiqueta = vData
End Property

Public Property Get imprimeEtiqueta() As Boolean
    imprimeEtiqueta = mvarimprimeEtiqueta
End Property

Public Property Let Grupo(ByVal vData As Byte)
    mvarGrupo = vData
    If vData > 0 Then LeeCamposTraza vData
End Property

Public Property Let ElemTrz(ByVal vData As Long)
    mvarElemTrz = vData
End Property

Public Property Get ElemTrz() As Long
    ElemTrz = mvarElemTrz
End Property

Public Property Get Grupo() As Byte
    Grupo = mvarGrupo
End Property

Public Property Get MaxIndices() As Integer
    MaxIndices = mvarMaxIndice
End Property

Private Sub Class_Terminate()
    Erase mvarTC
End Sub
